#!/bin/bash
#
echo ''
echo "`basename $0` ver 1.0"
echo 'Script to check the convergence w.r.t. k-mesh size.'
echo "Usage:"
echo "   `basename $0` eng_k.dat"
echo 'The first column should be the k-mesh size,'
echo 'the second column should be energy/cell in unit of eV.'
echo ''
echo 'Author: LT Kong, konglt@sjtu.edu.cn'
echo ''

if [ ! -f "eng_k.dat" ]; then
   echo "`basename $0`"
   echo "Script to check the convergence w.r.t. k-mesh size."
   echo "A file named eng_k.dat is required, while not found."
   exit 0
fi
#
cat > .gnuplot.scr << EOF
set terminal postscript enhanced color 20
set out 'conv_k.eps'

set xlabel 'k-size'
set ylabel 'Energy (eV/cell)'

plot 'eng_k.dat' u 1:2 w lp pt 7 ps 2 t ''
EOF

# gnuplot is employed to draw the figure
gnuplot .gnuplot.scr;  rm -rf .gnuplot.scr

# visualize the figure by using evince
if [ -f "conv_k.eps" ]; then
   evince conv_k.eps
fi

exit 0
